'##############
'Wiper Script
'##############

'Controls Wiper

'(c) 20.03.2009 Marcel Kuhnt

'Script Version: 1.0
'Omsi release: 1.0

'Needs:
'- rain
'- dirt

'Revision History:
'- Marcel Kuhnt		20.03.2009	Last Change		
'- Marcel Kuhnt		13.06.2009	Added Switch-Vars	
'- Marcel Kuhnt		13.06.2009	Added Wiper/Washer Function
'- Marcel Kuhnt		21.06.2009	Added AI-Activation
'- Rüdiger Hülsmann	14.05.2010	Added wiperpos_2xspeed for sinusdial movement during half a period

'--------------------------------------------------------------

{macro:wiper_L_init}
	0 (S.L.wiperrun)
{end}

{macro:wiper_L_frame}

'-------------------------------------------
'AI-Einfluss auf den Scheibenwischer:
'Nur wenn Motor an sein soll:
	(L.L.AI) (L.L.AI_Engine) 1 = &&
	{if}
'Wenn der Intervallwischer nicht ausreicht, dann Dauermodus:
		(C.L.wiper_intervall) (L.L.PrecipRate) * (C.L.rain_wiper_eff) >
		{if}
			0 (S.L.wiper_intervall_sw)
			1 (S.L.wiper_einaus_sw)
		{else}
'Sonst (falls es regnet) den Intervallmodus:
		(L.L.PrecipRate) 0 >
		{if}
			0 (S.L.wiper_intervall_sw)
			1 (S.L.wiper_einaus_sw)
		{else}
			0 (S.L.wiper_intervall_sw)
			0 (S.L.wiper_einaus_sw)
		{endif}
		{endif}
	{endif}

	(L.L.elec_busbar_main) 
	{if}	
		(L.L.wiperrunning) 1 =
		{if}
			(L.L.wiperrun) (L.S.Timegap) (L.L.wiper_speed) * + (S.L.wiperrun)
		{endif}

	
(L.L.wiperrun) 2 pi * >
		{if}
			(L.L.wiper_einaus_sw) (L.L.wiper_wascher_sw) || (S.L.wiperrunning)
			0 (S.L.wiperrun) (S.L.wiperrunning)
		{endif}
	
		
	
		(L.L.wiperrunning) ! (L.L.wiper_einaus_sw) (L.L.wiper_wascher_sw) || &&
		{if}
			1 (S.L.wiperrunning)
			(T.L.wiper_start)
			(L.L.Rain_Window_Wiped_Wetness_L) 0 =
			{if}
				(T.L.wiper_start_dry)
			{endif}
		{endif}

		(L.L.wiper_wascher_sw)
		{if}
			(L.L.wiper_wash) !
			{if}
				(T.L.wiper_wash_start)
			{endif}
			1 (S.L.wiper_wash)
			(L.L.wiper_wash_texpos) 3 (L.S.Timegap) * - (S.L.wiper_wash_texpos)
			1 (S.L.wiper_wash_R)
			(L.L.wiper_wash_texpos_R) 3 (L.S.Timegap) * - (S.L.wiper_wash_texpos_R)
		{else}
			0 (S.L.wiper_wash)
			0 (S.L.wiper_wash_R)
		{endif}

'		Wischer Intervall
		(L.L.wiper_intervall_sw) (L.L.wiper_intervall_on) ! && (L.L.wiper_intervall_time) (C.L.wiper_intervall) > ||
		{if}
		(L.L.wiperrunning) !
		{if}
			(T.L.wiper_start)
			(L.L.Rain_Window_Wiped_Wetness_L) 0 =
			{if}
				(T.L.wiper_start_dry)
			{endif}
		{endif}
		1 (S.L.wiper_intervall_on) (S.L.wiperrunning)
		(L.S.GetTime) (S.L.wiper_intervall_starttime)


	{endif}

	{else}
		0 (S.L.wiperrunning)
	{endif}


	(L.L.wiperrun) 1.5 pi * + sin 1 + 2 / (S.L.wiperpos) (S.L.Rain_Wiper_Pos_L) (S.L.Dirt_Wiper_Pos_L) 

	(L.L.wiperrun) 2 * 1.5 pi * + sin 1 + 2 / (S.L.wiperpos_2xspeed)

'	Wischer schnell

	(L.L.wiper_schnell_sw) (L.L.wiper_einaus_sw) &&
	{if}
		4.5 (S.L.wiper_speed)
	{else}
		3.5 (S.L.wiper_speed)
	{endif}




	
	(L.L.wiper_intervall_sw) !
	{if}
		0 (S.L.wiper_intervall_on)
	{endif}

	(L.L.wiper_intervall_on)
	{if}
		(L.S.getTime) (L.L.wiper_intervall_starttime) - (S.L.wiper_intervall_time)
	{else}
		0 (S.L.wiper_intervall_time)
	{endif}







'Wiper function (wetness remove):	

	(L.L.Rain_Window_Wiped_Wetness_L)	
'   Calc Diff.:
	(L.L.Rain_Wiper_Pos_L) (L.L.Rain_wiper_Pos_Prev_L) - abs
'   Multiply with wiper effectivity
	(C.L.rain_wiper_eff) *
'   Subtract and set
	 -
	0 max
	(S.L.Rain_Window_Wiped_Wetness_L)

	(L.L.Rain_Wiper_Pos_L) (S.L.Rain_Wiper_Pos_Prev_L)


'Wiper function (dirt remove):	

	(L.L.Rain_Window_Wiped_Wetness_L) (L.L.wiper_wascher_sw) (L.L.wiperrunning) && ||
	{if}
	
		(L.L.Dirt_Wiped_L)	
'  	Calc Diff.:
		(L.L.Dirt_Wiper_Pos_L) (L.L.Dirt_wiper_Pos_Prev_L) - abs
'   	Multiply with wiper effectivity
		(C.L.Dirt_wiper_eff) *
'  	Subtract and set
		 -
		0 max
		(S.L.Dirt_Wiped_L)
	
		(L.L.Dirt_Wiper_Pos_L) (S.L.Dirt_Wiper_Pos_Prev_L)
	{endif}


'Washer wetness

	(L.L.wiper_wash)
	{if}
		(L.S.Timegap) 0.5 * s0
		(L.L.Rain_Window_Front_Wetness) l0
		+ 1 min 0 max
		(S.L.Rain_Window_Front_Wetness)
		(L.L.Rain_Window_Front_Wetness_L) l0
		+ 1 min 0 max
		(S.L.Rain_Window_Front_Wetness_L)
(L.L.Rain_Window_Front_Wetness_R) l0
		+ 1 min 0 max
		(S.L.Rain_Window_Front_Wetness_R)
	
		(L.S.Timegap) s0

		(L.L.Rain_Window_Wiped_Wetness) l0
		+ 1 min 0 max
		(S.L.Rain_Window_Wiped_Wetness)
		(L.L.Rain_Window_Wiped_Wetness_L) l0
		+ 1 min 0 max
		(S.L.Rain_Window_Wiped_Wetness_L)
		(L.L.Rain_Window_Wiped_Wetness_R) l0
		+ 1 min 0 max
		(S.L.Rain_Window_Wiped_Wetness_R)


	{endif}
	
{end}
